<%--
  Created by IntelliJ IDEA.
  User: Sn
  Date: 2022/9/19
  Time: 15:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<button id="btnAdd">添加</button>
<table border="1px" width="50%">
    <tr>
        <td>学号</td>
        <td>姓名</td>
        <td>年龄</td>
        <td>性别</td>
        <td>分数</td>
        <td>操作</td>
    </tr>
    <!--requestScope.stus接收从StuViewController的stus-->
    <c:forEach items="${requestScope.stus}" var="stu">
        <tr>
            <td>${stu.id}</td>
            <td>${stu.name}</td>
            <td>${stu.age}</td>
            <td>${stu.sex}</td>
            <td>${stu.score}</td>
            <td><button type="button" onclick="del(${stu.id})">删除</button>&nbsp;&nbsp;
                <button type="button"onclick="edit(${stu.id})">修改</button></td>
        </tr>
    </c:forEach>

</table>
</body>
</html>
<script>
    var btnAdd=document.getElementById("btnAdd");
    btnAdd.addEventListener("click",function () {
        window.location="/stuAdd.jsp";
    })

    function del(id){
       var isDel=window.confirm("确定要删除吗?");
       if(isDel){
        window.location="/stu/del.action?id="+id;
       }
    }
    function edit(id){
        window.location="/stu/get.action?id="+id;
    }
</script>